package com.bcxj.serviceuser.controller;

import com.bcxj.internalcommon.constant.CommonConstant;
import com.bcxj.internalcommon.dto.TravelUserDTO;
import com.bcxj.internalcommon.dto.VerificationCodeDTO;
import com.bcxj.internalcommon.entity.TravelUser;
import com.bcxj.internalcommon.response.ResponseResult;
import com.bcxj.internalcommon.vo.TravelUserVO;
import com.bcxj.serviceuser.service.UserService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.xiaoleilu.hutool.util.BeanUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.catalina.User;
import org.apache.commons.beanutils.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * ClassName: UserController
 * Package: com.bcxj.serviceuser.controller
 * Description:
 *
 * @Author BCXJ
 * @Create 2025/2/12 21:41
 * @Version 1.0
 * @Since 1.0
 */
@Slf4j
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService travelUserService;

    @PostMapping
    public ResponseResult loginOrRegister(@RequestBody VerificationCodeDTO verificationCodeDTO) {
        log.info("需要注册的用户手机号为：" + verificationCodeDTO.getUserPhone());
        return travelUserService.loginOrRegister(verificationCodeDTO);
    }


    /**
     * 更新用户的信息
     * @param user
     * @return
     */
    @PostMapping("update")
    public ResponseResult updateUser(@RequestBody TravelUserDTO user) {
        TravelUser travelUser = new TravelUser();
        BeanUtil.copyProperties(user, travelUser);
        return travelUserService.updateUser(travelUser);
    }


    /**
     * 获取用户的信息
     * @param userPhone
     * @return
     */
    @GetMapping("get")
    public ResponseResult<TravelUserVO> getUser(@RequestParam String userPhone) {
        return travelUserService.getUserVOByUserphone(userPhone);
    }


    /**
     * 获取用户列表
     * @param pageNo
     * @return
     */
    @GetMapping("/list/{pageNo}")
    public ResponseResult list(@PathVariable("pageNo") Integer pageNo) {
        return travelUserService.list(pageNo);
    }


    /**
     * 禁言用户
     * @param id
     * @return
     */
    @GetMapping("state")
    public ResponseResult setState(Long id, Integer state) {
        return travelUserService.setState(id, state);
    }

}
